package com.lg.algorithm.collections.queue.disruptor;

import com.lmax.disruptor.RingBuffer;

public class Producer {
    
    private RingBuffer<Order> ringBuffer;
    
    public Producer(RingBuffer<Order> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void sendData(String uuid) {
        long sequence = -1L;
        try {
            System.out.println(Thread.currentThread().getId() + " --> " + ringBuffer.getCursor());
            sequence = ringBuffer.next();
            System.out.println(Thread.currentThread().getId() + " ----------> " + sequence);
            Order order = ringBuffer.get(sequence);

            order.setId(uuid);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ringBuffer.publish(sequence);
        }
    }

}